home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: scutler@ix.netcom.com (Scott Cutler)
- Newsgroups: comp.lang.c
- Subject: Re: sqrt() cheesy question
- Date: Sun, 25 Feb 1996 01:30:04 GMT
- Organization: Netcom
- Message-ID: <312fbb8c.7016394@nntp.ix.netcom.com>
- References: <4gjmmt$lt7@hopi.dtcc.edu>
- NNTP-Posting-Host: sac-ca9-22.ix.netcom.com
- X-NETCOM-Date: Sat Feb 24 5:31:09 PM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- On 23 Feb 1996 01:26:37 -0500, w4582@hopi.dtcc.edu (Rob Wiltbank)
- wrote:
-
- >Howdy all. I'm in a bind.
- >
- >I'm in a beggining C course at school, and I'm about 2 weeks ahead of the
- >class so I'm doing projects that the class hasn't even considered going
- >over yet. I'm still on the very newbie side of it all.
- >
- >Could someone post the function definition of the sqrt() function found
- >in math.h?
- >
- >Thanks.
- >
- >Rob
-
- I believe that most of the functions in math.h are written in assembly
- language, so you probably wouldn't understand them. However, if
- you're looking for a function that takes the square root, try this:
-
- double sqrt(double z)
- {
- int
- count;
- double
- y=0,
- x=1,
- precision=.000000000001;
- while(1)
- {
- x=x-(x*x-z)/(2*x)
- if(abs(z-x*x)<precision) break;
- }
-
- return x;
- }
- It's not super-efficient, but it works.
-
- Scott Cutler SCutler@ix.netcom.com
-